home *** CD-ROM | disk | FTP | other *** search
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include <iac.h>
- #include "appletdefs.h"
- #include "appletstrings.h"
- #include "appletmemory.h"
- #include "appletfrontier.h"
-
-
-
-
- typedef struct versionRecord {
-
- unsigned short majorRev: 8;
-
- unsigned short minorRev: 4;
-
- unsigned short bugFixRev: 4;
-
- unsigned short reserved: 15;
-
- unsigned short flFrontier: 1; /*true if it's Frontier, false if it's Runtime*/
- } versionRecord;
-
-
- #define frag1 "\pif not defined ("
-
- #define frag2 "\p) {speaker.beep (); return;}; Frontier.bringToFront (); edit (@"
-
- #define frag3 "\p)"
-
-
- boolean FrontierOpenObject (bigstring objectaddress) {
-
- bigstring script, returns;
-
- setstringlength (script, 0);
-
- pushstring (frag1, script);
-
- pushstring (objectaddress, script);
-
- pushstring (frag2, script);
-
- pushstring (objectaddress, script);
-
- pushstring (frag3, script);
-
- FrontierDoScript (script, returns);
- } /*FrontierOpenObject*/
-
-
- boolean FrontierDoScript (bigstring script, bigstring returns) {
-
- /*
- Send a Do Script message to Frontier. The first parameter contains a short
- script to be run. The second parameter is the string that Frontier returned
- as the value generated by running the script.
-
- Returns true if we were able to send the message to Frontier, and Frontier
- was able to compile and run the script and Frontier replied with a returned
- value. FrontierDoScript returns false if Frontier isn't running, or if the
- script didn't compile or if there was a communications error.
-
- Frontier is not limited to running 255-character scripts or returning
- 255-character returned values. This routine can easily be enhanced to handle
- larger scripts and returned values.
-
- 11/6/91 DW: Set return string to "IAC Error" if we failed to create an Apple
- event descriptor or if the send failed. We're not suggesting that your
- error messages should be so brief, rather they should be custom-fit to the
- appropriate audience. Here, we want to show you how to locate errors relating
- to the IAC channel -- either you're low on memory, or the Apple Event Manager
- isn't present, or Frontier isn't running. Watch for this string in FDS's
- little window...
-
- 11/7/91 DW: This code was cribbed from the Frontier Do-Script program and adapted
- to run on top of the IAC Tools library. Use this version of FDS if you're using
- the IAC Tools library, use the original version if you're writing code to run
- directly on top of the Apple Event Manager.
- */
-
- register Boolean flhavereply = false;
- AppleEvent event, reply;
-
- copystring ("\pIAC Error.", returns); /*default return string*/
-
- if (!IACnewverb ('LAND', 'misc', 'dosc', &event))
- return (false);
-
- IACglobals.event = &event;
-
- if (!IACpushstringparam (script, '----'))
- return (false);
-
- if (!IACsendverb (&event, &reply))
- goto error;
-
- flhavereply = true;
-
- IACglobals.reply = &reply;
-
- if (IACiserrorreply (returns)) /*syntax error or runtime error*/
- goto error;
-
- IACglobals.event = &reply; /*get the string from the reply record*/
-
- if (!IACgetstringparam ('----', returns))
- goto error;
-
- AEDisposeDesc (&event);
-
- AEDisposeDesc (&reply);
-
- return (true);
-
- error:
-
- AEDisposeDesc (&event);
-
- if (flhavereply)
- AEDisposeDesc (&reply);
-
- return (false);
- } /*FrontierDoScript*/
-
-
- boolean FrontierDoHandleScript (Handle hscript, boolean flfast, boolean flgetreturn, bigstring errorstring, Handle *hreturns) {
-
- AppleEvent event, reply;
- boolean fl = true;
-
- setstringlength (errorstring, 0);
-
- if (flfast) {
-
- if (!IACnewsystemverb ('fast', 'dosc', &event))
- return (false);
- }
- else {
-
- if (!IACnewverb ('LAND', 'misc', 'dosc', &event))
- return (false);
- }
-
- IACglobals.event = &event;
-
- if (!IACpushtextparam (hscript, '----'))
- return (false);
-
- if (!IACsendverb (&event, &reply))
- return (false);
-
- IACglobals.reply = &reply;
-
- if (IACiserrorreply (errorstring)) {
-
- fl = false;
-
- goto exit;
- }
-
- if (flgetreturn) {
-
- IACglobals.event = &reply; /*get the string from the reply record*/
-
- fl = IACgettextparam ('----', hreturns);
-
- if (fl)
- fl = copyhandle (*hreturns, hreturns);
- }
-
- exit:
-
- AEDisposeDesc (&event);
-
- AEDisposeDesc (&reply);
-
- return (fl);
- } /*FrontierDoHandleScript*/
-
-
- boolean FrontierFastDoScript (bigstring bsscript, boolean flgetreturn, bigstring errorstring, bigstring bsreply) {
-
- /*
- send a fast system-level script to Frontier and get back a value if flgetreturn is
- true. we only send the message the fast way if there is a system handler installed.
-
- use this for scripts that don't open windows or display things in Frontier. it's
- good for setting and getting string values in the object database.
- */
-
- AppleEvent event, reply;
- boolean fl = true;
-
- setstringlength (errorstring, 0);
-
- if (IAChandlerinstalled ('fast', 'dosc', true)) {
-
- if (!IACnewsystemverb ('fast', 'dosc', &event))
- return (false);
- }
- else {
-
- if (!IACnewverb ('LAND', 'misc', 'dosc', &event))
- return (false);
- }
-
- IACglobals.event = &event;
-
- if (!IACpushstringparam (bsscript, '----'))
- return (false);
-
- if (!IACsendverb (&event, &reply))
- return (false);
-
- IACglobals.reply = &reply;
-
- if (IACiserrorreply (errorstring)) {
-
- fl = false;
-
- goto exit;
- }
-
- if (flgetreturn) {
-
- IACglobals.event = &reply; /*get the string from the reply record*/
-
- fl = IACgetstringparam ('----', bsreply);
- }
-
- exit:
-
- AEDisposeDesc (&event);
-
- AEDisposeDesc (&reply);
-
- return (fl);
- } /*FrontierFastDoScript*/
-
-
- boolean FrontierIsRunning (void) {
-
- /*
- return true if the server application is running.
- */
-
- ProcessInfoRec info;
- ProcessSerialNumber psn;
- Str255 bsname;
- FSSpec fss;
-
- info.processInfoLength = sizeof (info);
-
- info.processName = bsname; /*place to store process name*/
-
- info.processAppSpec = &fss; /*place to store process filespec*/
-
- psn.highLongOfPSN = kNoProcess;
-
- psn.lowLongOfPSN = kNoProcess;
-
- while (GetNextProcess (&psn) == noErr) {
-
- info.processInfoLength = sizeof (ProcessInfoRec);
-
- if (GetProcessInformation (&psn, &info) != noErr)
- continue; /*keep going -- ignore error*/
-
- if (info.processSignature == 'LAND')
- return (true);
- } /*while*/
-
- return (false); /*loop completed, no Frontier*/
- } /*FrontierIsRunning*/
-
-
- boolean getFrontierVersion (short *majorRev, short *minorRev, short *bugFixRev, boolean *flRuntime) {
-
- /*
- if Frontier isn't running, return false.
-
- if it is, return true with information about the version of Frontier that's running.
-
- About the Apple Event we send...
-
- We call a system event handler, so it's very fast.
-
- It takes no parameters, and returns a long value. The high word of the long is the version
- number, packed the same way as the system version is packed into the SysEnvirons record.
- (8 bits major version, 4 bits minor version, 4 bits revision. The version 2.1.1 would
- be 0x0211.) The low word contains attributes of the server program. At this point only
- a single bit is defined: the low order bit is set if Frontier is the server; otherwise,
- Runtime is the server.
- */
-
- AppleEvent event, reply;
- Boolean flhavereply = false;
- versionRecord x;
-
- long z;
-
- z = sizeof (x);
-
- if (!FrontierIsRunning ())
- return (false);
-
- if (!IAChandlerinstalled ('LAND', 'who?', true)) { /*it's Frontier 1.0, not Runtime*/
-
- *majorRev = 1;
-
- *minorRev = 0;
-
- *bugFixRev = 0;
-
- *flRuntime = false;
-
- return (true);
- }
-
- if (!IACnewsystemverb ('LAND', 'who?', &event))
- return (false);
-
- if (!IACsendverb (&event, &reply))
- goto error;
-
- flhavereply = true;
-
- IACglobals.reply = &reply;
-
- IACglobals.event = &reply; /*get the string from the reply record*/
-
- if (!IACgetlongparam ('----', (long *) &x))
- goto error;
-
- *majorRev = x.majorRev;
-
- *minorRev = x.minorRev;
-
- *bugFixRev = x.bugFixRev;
-
- *flRuntime = !x.flFrontier;
-
- AEDisposeDesc (&event);
-
- AEDisposeDesc (&reply);
-
- return (true);
-
- error:
-
- AEDisposeDesc (&event);
-
- if (flhavereply)
- AEDisposeDesc (&reply);
-
- return (false);
- } /*getFrontierVersion*/
-